home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
BORL_TIP
/
TI2000
/
TI2717.ASC
< prev
next >
Wrap
Text File
|
1994-10-03
|
3KB
|
118 lines
PRODUCT : Pascal NUMBER : 2717
VERSION : All
OS : DOS
DATE : September 30, 1994 PAGE : 1/2
TITLE : Using your EXE as a resource file
{
This program demonstrates how to use your EXE
file as a resource. You should run this program
twice - once to write info to the EXE and once to
read info out.
}
program foo;
uses Objects;
type
PMyObject = ^TMyObject;
TMyObject = object(TObject)
AString: String;
constructor Init(S: String);
constructor Load(var S: TStream);
procedure Store(var S: TStream);
end;
constructor TMyObject.Init(S: String);
begin
inherited Init;
AString := S;
end;
constructor TMyObject.Load(var S: TStream);
begin
inherited Init;
S.Read(AString, SizeOf(AString));
end;
procedure TMyObject.Store(var S: TStream);
begin
S.Write(AString, SizeOf(AString));
end;
const
PRODUCT : Pascal NUMBER : 2717
VERSION : All
OS : DOS
DATE : September 30, 1994 PAGE : 2/2
TITLE : Using your EXE as a resource file
RMyObject: TStreamRec = (
ObjType: 100;
VmtLink: Ofs(TypeOf(TMyObject)^);
Load: @TMyObject.Load;
Store: @TMyObject.Store);
var
Rez: PResourceFile;
TheStream: PBufStream;
AObject, Obj: PMyObject;
begin
{ Register my object for streaming }
RegisterType(RMyObject);
{ Create instace of my object }
Obj := New(PMyObject, Init('Hello world'));
{ Create instance of a stream pointing to EXE file }
TheStream := New(PBufStream, Init(ParamStr(0), stOpen, 1024));
{ was stream created okay? }
if TheStream^.Status = stOk then begin
{ Crate instance of resource file }
Rez := New(PResourceFile, Init(TheStream));
{ try to grab object from resource stream }
AObject := PMyObject(Rez^.Get('My Object'));
if AObject <> nil then
{ if found, then write object's string to screen }
writeln('The magic string is: ' + AObject^.AString)
else
{ if not, then write object to resource }
Rez^.Put(Obj, 'My Object');
end;
{ clean up }
Obj^.Free;
Rez^.Free;
end.
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.